<?php

use Biz\service\Store\StoreBasicService;
use Doraemon\tools\HhzClient;

/**
 * 甄选门店
 * Class ListAction
 */
class FeaturedStoreAction extends ActionPlugin
{
    public const USER_LEVEL = self::LEVEL_NOTHING;

    /**
     * @throws Exception
     */
    public function main()
    {
        $pageSize = 20;
        $page = $this->getRequest()->getQuery('page', 1);
        $location = $this->getRequest()->getQuery('location', '');
        $locationArr = explode(',', $location);
        $longitude = '';
        $latitude = '';
        if ($locationArr && count($locationArr) == 2) {
            $longitude = $locationArr[0];
            $latitude = $locationArr[1];
        }
        list($list, $total) = $this->getStore($page, $pageSize, $longitude, $latitude);
        $data = [
            'banner' => $this->getBanner(),
            'list' => $list,
            'is_over' => $page * $pageSize >= $total ? 1 : 0
        ];
        return $this->setSuccess($data);
    }

    private function getStore($page, $pageSize, $longitude, $latitude)
    {
        list($list, $total) = StoreBasicService::getNearbyStoreList($page, $pageSize, $longitude, $latitude);
        return [$list, $total];
    }

    private function getBanner()
    {
        $banner = [];
        if (HhzClient::getClientType() == HhzClient::APPTYPE_STORE_MINIPROGRAM) {
//            $banner = [
//                [
//                    'id' => 1,
//                    'banner' => 'https://img.haohaozhu.cn/Op-imageShow/38d4030j405g0pm00qtas5b?iv=1',
//                    'link' => 'https://m.haohaozhu.cn/brand/new-product-express',
//                    'statSign' => '',
//                ]
//            ];
        } else {
//            $banner = [
//                [
//                    'id' => 1,
//                    'banner' => 'https://img.haohaozhu.cn/Op-imageShow/38d4030j405g0pm00qtas5b?iv=1',
//                    'link' => '',
//                    'statSign' => '',
//                ]
//            ];
        }
        return $banner;
    }

}